package com.dks.repository.impl.teacher;

import com.dks.dto.student.StudentEvaluateDto;
import com.dks.enumeration.DictionaryType;
import com.dks.mapper.EvaluateMapper;
import com.dks.mapper.PublicDictionaryMapper;
import com.dks.repository.IEvaluateRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;
import com.dks.util.PageInfo;
import com.dks.vo.teacher.EvaluateDetailVo;
import com.dks.vo.teacher.EvaluateVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class EvaluateRepository implements IEvaluateRepository {

    @Autowired
    private EvaluateMapper evaluateMapper;

    @Autowired
    private PublicDictionaryMapper publicDictionaryMapper;


    /***
     * 评价列表
     * @author evan
     */
    @Override
    public ResultModel<PageInfo<EvaluateVo>> list(Long teacherId, Long qsClassId, Long studentId, Integer pageNum, Integer pageSize) {
        Page p = PageHelper.startPage(pageNum, pageSize);
        List<EvaluateVo> evaluateList = evaluateMapper.list(teacherId, qsClassId, studentId);
        PageInfo<EvaluateVo> pageInfo = new PageInfo<>(pageNum,pageSize,p.getTotal(),p.getPages(),evaluateList);
        return Result.makeResult(ResultInfo.SUCCESS, pageInfo);
    }

    /**
     * 创建学生评价
     * @param studentEvaluateDto
     * @return
     */
    @Override
    public ResultModel<Object> addStudentEvaluate(StudentEvaluateDto studentEvaluateDto) {
        try{
            evaluateMapper.insert(studentEvaluateDto);
        }catch (Exception e){
            return Result.makeResult(ResultInfo.ERR_EVALUATE_001);
        }
        return Result.makeResult(ResultInfo.SUCCESS);
    }

    @Override
    public ResultModel<Object> getAllLabels() {
        return Result.makeResult(ResultInfo.SUCCESS,publicDictionaryMapper.getByType("TEACHER_LABEL"));
    }

    /***
     * 评价详情
     * @author evan
     */
    @Override
    public ResultModel<EvaluateDetailVo> select(Long id) {
        EvaluateDetailVo evaluateDetailVo = evaluateMapper.select(id);
        return Result.makeResult(ResultInfo.SUCCESS, evaluateDetailVo);
    }
}
